home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / TIME.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  2KB  |  93 lines

  1. #ifndef _LINUX_TIME_H
  2. #define _LINUX_TIME_H
  3.  
  4. #include <asm/param.h>
  5. #include <linux/types.h>
  6.  
  7. #ifndef _STRUCT_TIMESPEC
  8. #define _STRUCT_TIMESPEC
  9. struct timespec {
  10.     time_t    tv_sec;        /* seconds */
  11.     long    tv_nsec;    /* nanoseconds */
  12. };
  13. #endif /* _STRUCT_TIMESPEC */
  14.  
  15. /*
  16.  * Change timeval to jiffies, trying to avoid the
  17.  * most obvious overflows..
  18.  *
  19.  * And some not so obvious.
  20.  *
  21.  * Note that we don't want to return MAX_LONG, because
  22.  * for various timeout reasons we often end up having
  23.  * to wait "jiffies+1" in order to guarantee that we wait
  24.  * at _least_ "jiffies" - so "jiffies+1" had better still
  25.  * be positive.
  26.  */
  27. #define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
  28.  
  29. static __inline__ unsigned long
  30. timespec_to_jiffies(struct timespec *value)
  31. {
  32.     unsigned long sec = value->tv_sec;
  33.     long nsec = value->tv_nsec;
  34.  
  35.     if (sec >= (MAX_JIFFY_OFFSET / HZ))
  36.         return MAX_JIFFY_OFFSET;
  37.     nsec += 1000000000L / HZ - 1;
  38.     nsec /= 1000000000L / HZ;
  39.     return HZ * sec + nsec;
  40. }
  41.  
  42. static __inline__ void
  43. jiffies_to_timespec(unsigned long jiffies, struct timespec *value)
  44. {
  45.     value->tv_nsec = (jiffies % HZ) * (1000000000L / HZ);
  46.     value->tv_sec = jiffies / HZ;
  47. }
  48.  
  49. struct timeval {
  50.     time_t        tv_sec;        /* seconds */
  51.     suseconds_t    tv_usec;    /* microseconds */
  52. };
  53.  
  54. struct timezone {
  55.     int    tz_minuteswest;    /* minutes west of Greenwich */
  56.     int    tz_dsttime;    /* type of dst correction */
  57. };
  58.  
  59. #define NFDBITS            __NFDBITS
  60.  
  61. #ifdef __KERNEL__
  62. extern void do_gettimeofday(struct timeval *tv);
  63. extern void do_settimeofday(struct timeval *tv);
  64. extern void get_fast_time(struct timeval *tv);
  65. extern void (*do_get_fast_time)(struct timeval *);
  66. #endif
  67.  
  68. #define FD_SETSIZE        __FD_SETSIZE
  69. #define FD_SET(fd,fdsetp)    __FD_SET(fd,fdsetp)
  70. #define FD_CLR(fd,fdsetp)    __FD_CLR(fd,fdsetp)
  71. #define FD_ISSET(fd,fdsetp)    __FD_ISSET(fd,fdsetp)
  72. #define FD_ZERO(fdsetp)        __FD_ZERO(fdsetp)
  73.  
  74. /*
  75.  * Names of the interval timers, and structure
  76.  * defining a timer setting.
  77.  */
  78. #define    ITIMER_REAL    0
  79. #define    ITIMER_VIRTUAL    1
  80. #define    ITIMER_PROF    2
  81.  
  82. struct  itimerspec {
  83.         struct  timespec it_interval;    /* timer period */
  84.         struct  timespec it_value;       /* timer expiration */
  85. };
  86.  
  87. struct    itimerval {
  88.     struct    timeval it_interval;    /* timer interval */
  89.     struct    timeval it_value;    /* current value */
  90. };
  91.  
  92. #endif
  93.